<template>
  <component :is="current" :ref="current" v-model="innerValue" :cfg="cfg" />
</template>
<script>
import { CQ_EVAL_DATA_TYPE } from '@/utils/baseData'
import NumScore from './NumberScore'
import EnumScore from './EnumScore'
import AddSubObj from './AddSubObj'
export default {
  name: 'ScoreMode',
  components: { NumScore, EnumScore, AddSubObj },
  props: {
    value: { type: Object, default: () => ({}) },
    cfg: { type: Object, default: () => ({}) }
  },
  computed: {
    innerValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    },
    current() {
      const { dataType, addsubObj } = this.cfg || {}
      if (addsubObj) return 'AddSubObj'
      if (dataType === CQ_EVAL_DATA_TYPE.ENUM) return 'EnumScore'
      return 'NumScore'
    }
  },
  methods: {
    async validate() {
      return this.$refs[this.current]?.validate()
    }
  }
}
</script>
